// FTPDownload(remotePath, localPath, host, user, password)
//
// Download a file via FTP. Requires SmartPill PHP plugin.
//
// Returns:
//		 0		Successful
//		-1		Couldn't log in to the FTP server
//		-2		Couldn't download the file from the FTP server
//
Let (
	[
		$localPath = localPath ;
		$remotePath = remotePath ;
		$host = host ;
		$user = user ;
		$password = password ;

		phpCode = "error_reporting(0); //(E_ALL & ~E_NOTICE);¶
		¶
		$localPath = fm_evaluate('$localPath');¶
		$remotePath = fm_evaluate('$remotePath');¶
		$host = fm_evaluate('$host');¶
		$user = fm_evaluate('$user');¶
		$password = fm_evaluate('$password');¶
		¶
		$retVal = 0;¶
		$connection = ftp_connect($host);¶
		¶
		$login_result = @ftp_login($connection, $user, $password);¶
		if ((!$connection) || (!$login_result))¶
		{¶
			$retVal = -1;¶
		}¶
		else¶
		{¶
			ftp_pasv($connection, true);¶
			¶
			if (!ftp_get($connection, $localPath, $remotePath, FTP_BINARY))¶
			{¶
				$retVal = -2;¶
			}¶
			¶
			ftp_close($connection);¶
		}¶
		echo $retVal;¶
	  ";

		result = PHP_Execute(phpCode)
	] ;
	result
)